myApp.controller('ProdCleanController', function ($scope, $stateParams, ngDialog, $http, $uibModal, $interval) {
    $scope.info = {};
    $scope.info.schemaList = [];
    $scope.info.schemaInfo = {};
    $scope.info.initList = [];

    $scope.info.envType = "DEVTEST";

    //查询库列表
    $scope.getSchemaList = function () {
        doBeetleGet($http, $uibModal, beetle_plan_url + '/prod/schema', function (data) {
            if (data.success) {
                $scope.info.schemaList = data.data;
                if ($scope.info.schemaList.length > 0) {
                    $scope.info.schemaInfo = $scope.info.schemaList[0];
                    $scope.getInitList();
                }
            } else {
                openDialogAlert(ngDialog, $scope, data.msg);
            }
        })
    };

    $scope.getSchemaList();

    $scope.getInitList = function () {
        doBeetleGet($http, $uibModal, beetle_plan_url + '/prod/init?schemaName=' + $scope.info.schemaInfo.table_schema + '&envType=' + $scope.info.envType, function (data) {
            if (data.success) {
                $scope.info.initList = data.data;
            } else {
                openDialogAlert(ngDialog, $scope, data.msg);
            }
        })
    };

    $scope.schemaSelect = function () {
        $scope.getInitList();
    };

    $scope.changeActive = function (info, active) {
        openDialog(ngDialog, $scope, "确定要设置成" + active == 'N' ? "无效" : "有效" + "吗？", true, function (val) {
            if (!val) {
                return;
            }
            info.is_active = active;
        });
    };

    $scope.save = function (info) {
        openDialog(ngDialog, $scope, "确定要保存修改吗？", true, function (val) {
            if (!val) {
                return;
            }
            var data = {};
            angular.copy(info, data);
            data.updatedby = getUserAccount();
            console.log(data);
            doBeetlePost($http, $uibModal, beetle_plan_url + '/prod/init', data, function (data) {
                if (data.success) {
                    openDialogAlert(ngDialog, $scope, "保存成功");
                } else {
                    openDialogAlert(ngDialog, $scope, data.msg);
                }
            });
        })
    };
});